import requests
import yaml
import os
def get_test_data(test_data_path):
    case = []  # 存储测试用例名称
    http = []  # 存储请求对象
    expected = []  # 存储预期结果
    with open(test_data_path,"r",encoding="utf-8") as f:
        data = yaml.load(f.read(), Loader=yaml.SafeLoader)        
        for td in data["tests"]:
            case.append(td.get('case', ''))
            http.append(td.get('http', {}))
            expected.append(td.get('expected', {}))
    
    parameters = zip(case, http, expected)
    return case, parameters

yaml_path=os.path.dirname(__file__)+"\\test.yaml"
cases, parameters = get_test_data(yaml_path)
list_params=list(parameters)

class TestInTheaters(object):
    def test_in_theaters(self):
        host = "http://api.douban.com"
        r = requests.request(list_params[0][1]["method"],
                             url=host + list_params[0][1]["path"],
                             headers=list_params[0][1]["headers"],
                             params=list_params[0][1]["params"])
        response = r.status_code
        print(response)
        
        # assert response["count"] == list_params[0][2]['response']["count"]
        # assert response["start"] == list_params[0][2]['response']["start"]
        # assert response["total"] == len(response["subjects"])
        # assert response["title"] == list_params[0][2]['response']["title"], "实际的标题是:{}".format(response["title"])